﻿using PRO.Admin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.Common;
using PRO.Entity;
using PRO.CashCoupon;

namespace web.Manage.Cash_coupon
{
    public partial class edit : ManageBase, ICallbackEventHandler
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ClientScript.GetCallbackEventReference(this, "", "", "");
        }
        public string CallbackResult = null;

        public void RaiseCallbackEvent(string eventArgument)
        {
            if (eventArgument.IsNullOrWhiteSpace())
                CallbackResult = "参数不正确！";
            else
            {
                string[] arg = eventArgument.Split(',');
                if (arg.Length == 2)
                {
                    if (!arg[0].IsPrice())
                        CallbackResult = "价格格式不正确！";
                    else
                    {
                        if (arg[1].ToInt(0) == 0)
                            CallbackResult = "请选择生成数量！";
                        else
                        {
                            int f = 0;
                            for (int i = 0; i < arg[1].ToInt(0); i++)
                            {
                                CashCouponInfo info = new CashCouponInfo();
                                info.CardNumber = CashCouponLib.CreateCardNumber();
                                info.CashPrice = arg[0].ToDecimal(0);
                                info.CreateTime = DateTime.Now;
                                if (CashCouponLib.CreateCashCoupon(info))
                                    f++;
                                else
                                    break;
                            }
                            CallbackResult = "成功创建" + f + "个,您可以返回“现有礼品卡”查看！";
                        }
                    }
                }
                else
                    CallbackResult = "参数不正确！";
            }
        }
        public string GetCallbackResult() { return CallbackResult; }
    }
}